import router from '../router'
import store from '../store'

// 设置一下无token可访问的路由列表
const whiteList = ['/login', '/main/dashboard']
router.beforeEach((to, from, next) => {
  console.log('to=', to)
  console.log(from)
  console.log(next())

  if (store.commit('getToken')) {
    console.log('token 已存在')
  } else {
    // 无token并且to.path不在白名单中,跳转到login去获取token,如果login不在白名单中,直接使用next('/login')则会造成死循环,先
    if (whiteList.includes(to.path)) {
      next()
    } else {
      next('/')
    }
  }
})
